using System;
using System.Collections;
using System.Collections.Generic;
using FrameWork;
using UnityEngine;

public class Fireball : MonoBehaviour, IBullet
{
    private float damage;
    public void SetDamage(float damage)
    {
        this.damage = damage;
    }

    private void OnEnable()
    {
        GetComponent<BoxCollider2D>().enabled = false;
        Invoke("Open",0.2f);
        Invoke("Close", 0.4f);
        Invoke("Dis", 0.8f);
    }

    private void Open()
    {
        GetComponent<BoxCollider2D>().enabled = true;
    }

    private void Close()
    {
        GetComponent<BoxCollider2D>().enabled = false;
    }

    private void Dis()
    {
        ObjectPool.Instance.Replace("Fireball", this.gameObject);
    }

    private void OnTriggerEnter2D(Collider2D other)
    {
        if (other != null && other.CompareTag("Player"))
        {
            other.GetComponent<IAttack>().Attack(damage);
        }
    }
}
